package org.example;

import java.util.Map;

/**
 * @author: longhc@citycloud.com.cn
 * @since: 2024/3/14 17:48
 * @version: 1.0
 */
public abstract class AbstractTicket implements Ticket {

    /**
     * 一票多柜
     */
    private static final String MULTIPLE_CONTAINERS = "M";


    /**
     * 一票一柜
     */
    private static final String SINGLE_CONTAINERS = "S";

    /**
     * 散装
     */
    private static final String type = "1";

    /**
     * 下订单
     *
     * @param map map
     */
    @Override
    public final void process(Map<String, String> map) {
        // 执行一票多柜
        if (MULTIPLE_CONTAINERS.equals(map.get("type"))) {
            processMultiple(map);
            return;
        }
        // 一票一柜
        processSingle(map);
    }

    /**
     * 一票多柜
     *
     * @param map Map<String, String>
     */
    private final void processSingle(Map<String, String> map) {
        // 散装
        if (type.equals(map.get("packaging_type"))) {
            relaxPackage(map);
            return;
        }
        entirePackage(map);
    }

    /**
     * 整装获取处理逻辑
     *
     * @param map Map<String, String>
     */
    protected abstract void entirePackage(Map<String, String> map);

    /**
     * 散装获取处理逻辑
     *
     * @param map Map<String, String>
     */
    protected abstract void relaxPackage(Map<String, String> map);

    /**
     * 一票一柜
     *
     * @param map Map<String, String>
     */
    private final void processMultiple(Map<String, String> map) {
        execute(map);
    }

    /**
     * 生成订单
     *
     * @param map Map<String, String>
     */
    protected abstract void execute(Map<String, String> map);
}
